import axios from 'axios';

axios.interceptors.request.use(function (config) {
    // 从本地获取token
    const token = window.localStorage.getItem('token');
    config.headers.authoraztion = token;
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Do something with response data
    const res = response.data;
    if (res.success) {
        return res;
    } else {
        alert(res.message)
    }
}, function (error) {
    // Do something with response error
    return Promise.reject(error);
});

export default axios